package query

// 二分法
func SqrtNumber(n float64, m int) float64 {
	// 此时n的开根数在x-2x之间
	low := float64(0)
	high := n
	mid := getMid(low, high)
	count := 50
	for count > 0 {
		z := mid * mid
		if z > n {
			high = mid
			mid = getMid(low, mid)
		} else if z < n {
			low = mid
			mid = getMid(low, high)
		} else if z == n {
			break
		}
		count--
	}
	return mid
}

func getMid(low, high float64) float64 {
	return low + (high-low)/2
}
